package com.yc.hwc.web;

import java.math.BigInteger;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.yc.hwc.bean.Article;
import com.yc.hwc.dao.IArticleDao;
import com.yc.hwc.dao.SqlDao;

@RestController
@RequestMapping(path={"hwctask/article","task/article"})
public class ArticleDo extends BaseAction<Article>{
	
	@Resource
	private SqlDao sdao;
	
	@GetMapping("new10")
	public List<Article> new10() {
		String sqlid = "ArticleNew10ForType";
		List<Map<String,Object>> list = sdao.list(sqlid);
		long[] ids = list.stream().mapToLong(map->{
			return ((BigInteger)map.get("id")).longValue();
		}).toArray();
		IArticleDao dao = (IArticleDao) biz.getDao();
		return dao.findByIdInOrderByReadCntDescIdDesc(ids);
	}
	
	@GetMapping("read")
	public void read(Integer id) {
		sdao.exec("update article set read_cnt=ifnull(read_cnt,0)+1 where id=?0", id);
	}

}
